﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebStore.Web.App.Utility.Other;

namespace WebStore.Web.App.Controllers
{
	public partial class CartController
	{
        public RedirectToRouteResult Add(int id,string returnUrl)
        {
            var product = _entities.Products.FirstOrDefault(x => x.Id == id);
            GetCart().Add(product,1);

            return RedirectToAction("Summary", new { returnUrl });
        }
        
        public RedirectToRouteResult Remove(int id,string returnUrl)
        {
            var product = _entities.Products.FirstOrDefault(x => x.Id == id);

            GetCart().Remove(product.Id,1);

            return RedirectToAction("Summary", new { returnUrl });

        }


        private Cart GetCart()
        {
            var cart = (Cart)Session["Cart"];
            if (cart == null)
            {
                cart = new Cart();
                Session["Cart"] = cart;
            }
            return cart;
        }
	}
}